package com.rookie.data.generate.component.generate;

import com.rookie.data.generate.component.AbstractAnnotationGenerate;
import com.rookie.data.generate.constant.annotation.ConstCollection;
import com.rookie.data.generate.model.project.TableColumnEntity;
import com.rookie.data.generate.util.GenerateUtils;
import org.springframework.stereotype.Component;

import java.lang.annotation.Annotation;

/**
 * @author rookie
 */
@Component
public class ConstCollectionGenerate extends AbstractAnnotationGenerate {

    @Override
    public Object generate(TableColumnEntity table, Annotation annotation){
        ConstCollection constCollection = (ConstCollection) annotation;
        String[] value = constCollection.value();
        int length = value.length;
        if (value.length < 1){
            return null;
        }
        int i = GenerateUtils.RANDOM.nextInt(length);
        return value[i];
    }

    @Override
    public Class<? extends Annotation> getAnnotationClass() {
        return ConstCollection.class;
    }

}
